package com.ztools.pc.controller.sys;

import cn.hutool.core.util.ArrayUtil;
import com.ztools.common.model.pc.sys.FileInfo;
import com.ztools.common.util.common.Result;
import com.ztools.pc.service.sys.FileInfoService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:一口香菜
 * @Date: 2023/3/25  12:19
 * @Version 1.0
 */
@RestController
@RequestMapping("/sys/file")
public class FileInfoController {

    @Resource
    private FileInfoService fileInfoService;

    @PostMapping("/upload")
    public Result uploadFile(MultipartFile[] files) {
        if (files == null || files.length < 1) {
            return Result.error("找不到文件!");
        }
        List<FileInfo> upload = fileInfoService.uploadFile(files);
        if (ArrayUtil.isNotEmpty(upload) && upload.size() > 0) {
            return Result.success("文件上传成功").data(upload);
        }
        return Result.error("文件上传失败");
    }

}
